Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubisoft OAuth integration #56

Merged
merged 27 commits into from
Jul 30, 2021
Merged

Ubisoft OAuth integration #56

merged 27 commits into from
Jul 30, 2021

Conversation

MKuijpers
Copy link
Collaborator

@MKuijpers MKuijpers commented Jul 28, 2021

Adds a "Login with Ubisoft" button to authenticate the user.

⚠ Requires .env changes! ⚠

OAuth requires you to create an application on api.trackmania.com:

Client:
NEXT_PUBLIC_CLIENT_ID=<CLIENT_ID from api.trackmania.com>

Server:
TM_API_CLIENT_ID=<CLIENT_ID from api.trackmania.com>
TM_API_CLIENT_SECRET=<CLIENT_SECRET from api.trackmania.com>

Flow Summary

  • Click "Login with Ubisoft"
  • Redirect to api.trackmania.com/... authentication URL
  • Login using Ubisoft credentials
  • Redirect back to <domain>/auth_redirect containing a code and state in query params
  • Send post request to TMDojo API /authorize endpoint
    • Exchange access code for an access token
    • Request user info
    • Create a session for respective user
    • Set HttpOnly sessionId cookie
    • Respond with user info
  • Send back sessionId cookie with further requests for authentication
    • Done using {withCredentials: true} config in axios (will create an axios interface with this default in a later PR)

New Endpoints

/authorize for first authentication
/logout to logout. Removes session and sends back a sessionId cookie with an age of -1 (instantly deletes cookie)
/me to fetch user information for the logged in user

@vercel
Copy link

vercel bot commented Jul 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/bux42/tm-dojo/hswTALSAgqDCjsK4U98hrUcwHAwv
✅ Preview: https://tm-dojo-git-ubi-auth-bux42.vercel.app

Copy link
Collaborator

@davidbmaier davidbmaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part, just a few minor things 👍

app/components/common/UserDisplay.tsx Outdated Show resolved Hide resolved
app/components/landing/InfoCard.tsx Outdated Show resolved Hide resolved
app/lib/api/auth.ts Outdated Show resolved Hide resolved
app/lib/api/auth.ts Outdated Show resolved Hide resolved
app/lib/api/auth.ts Outdated Show resolved Hide resolved
server/lib/db.js Outdated Show resolved Hide resolved
const sessions = db.collection('sessions');
const sessionId = uuid();
await sessions.insertOne({
sessionId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something we have to do right now, but I wonder if we should store the hash of the secret instead of the real session. Obviously that means we'd also have to change the validation when requests come in - let me know what you think.

server/middleware/auth.js Outdated Show resolved Hide resolved
server/lib/authorize.js Outdated Show resolved Hide resolved
server/lib/authorize.js Show resolved Hide resolved
@MKuijpers MKuijpers merged commit 6e2984d into staging Jul 30, 2021
@MKuijpers MKuijpers deleted the ubi-auth branch July 30, 2021 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants